import datetime


class DiaryData ():

    def __init__(self) -> None:
         self.DiaryList = [[],[]]
         self.LastDiary = [None,None]


    def AddDiary (self,identity,text,encryption,emotion,weather,style): #新增日记
        today = datetime.date.today()

        if self.LastDiary[identity] == today: #今天已经写过日记
            return 0 #一天不能写多次日记
        
        new_diary = {'Date':today,'Text':text,'Encryption':encryption,'Emotion':emotion,'Weather':weather,'Style':style}
        
        self.LastDiary[identity] = today
        self.DiaryList[identity].append(new_diary)

        return 1 #写入成功

    
    def ReadDiary (self,index,owner,identity): #读一页日记
        text = ''
        emotion = self.DiaryList[owner][index]['Emotion']
        weather = self.DiaryList[owner][index]['Weather']
        style = self.DiaryList[owner][index]['Style']
        encry = self.DiaryList[owner][index]['Encryption']
        if self.DiaryList[owner][index]['Encryption'] == 0 or owner == identity:
        #未加密或读取自己的日记
            text = self.DiaryList[owner][index]['Text']

        else:
            text = '内容加密'

        result_info = [text,emotion,weather,style,encry]

        return result_info

    
    def EncryptDiary (self,index,identity): #为日记加密
        self.DiaryList[identity][index]['Encryption'] = 1